﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using CE.Global;

public partial class Provider_CarInsurance_ViewProviderCarMakeModel : System.Web.UI.Page
{
    string PageName = "CXCI";
    string SubPageName = "CXCICMDL";
    protected void Page_Load(object sender, EventArgs e)
    {
        //usrLink.PageName = "View Provider Car Make Model";

        if (Session[CE.Global.General.UserId] == null || Session[CE.Global.General.ProviderCompanyId] == null)
        {
            Response.Redirect("~/Provider/ProviderSecureLogin.aspx");
        }
        CheckMainPageAccess();
        CheckSubPageAccess();

        if (!Page.IsPostBack)
        {
            GetProviderCarMake();

            if (Session[CE.Global.General.ProviderCompanyId].ToString() == "24")
            {
                lnkNew.NavigateUrl = "~/Provider/CarInsurance/ProviderCarMakeModelRSA.aspx";
                
            }
            
        }
    }
    protected void ibtBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("~/Provider/CarInsurance/TableMatching.aspx");
    }

    private void GetProviderCarMake()
    {
        CE.Provider.CarMakeList _carmakelist = new CE.Provider.CarMakeList();
        CE.Provider.CarMakeDB _carmakedb = new CE.Provider.CarMakeDB();

        _carmakelist = _carmakedb.GetProviderMakeList(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()));
        if (_carmakelist != null)
        {
            for (int i = 0; i < _carmakelist.Count; i++)
            {
                ddlProviderCarMake.Items.Add(new ListItem(_carmakelist[i].Description, _carmakelist[i].CarMakeId.ToString()));
            }
        }
        //CarMakeDB _providercarmakedb = new CarMakeDB();
        //DataTable dtCarMake = _providercarmakedb.GetCarMakeDT(Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()));
        //ddlCarMake.DataSource = dtCarMake;
        //ddlCarMake.DataTextField = "Description";
        //ddlCarMake.DataValueField = "CarMakeId";        
        //ddlCarMake.DataBind();

        ddlProviderCarMake.Items.Insert(0, new ListItem("Select", "-1"));
    }

    protected void GridView1_RowDatabound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("HSBCProviderCompanyId"))
            {
                e.Row.Cells[17].Text = "Accept";
            }
            else
            {
                e.Row.Cells[17].Text = "Status";
            }
        }
        else if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //* For test

            HyperLink hl = e.Row.Cells[20].Controls[0] as HyperLink;
            if (Session[CE.Global.General.ProviderCompanyId].ToString() == "24")
            {
                hl.NavigateUrl = string.Format("ProviderCarMakeModelRSA.aspx?CarMakeId={0}&CarModelId={1}&IsParallel={2}", DataBinder.Eval(e.Row.DataItem, "CarMakeId"), DataBinder.Eval(e.Row.DataItem, "CarModelId"), DataBinder.Eval(e.Row.DataItem, "IsParallel"));
            }
            else
            {                
                hl.NavigateUrl = string.Format("ProviderCarMakeModel.aspx?CarMakeId={0}&CarModelId={1}", DataBinder.Eval(e.Row.DataItem, "CarMakeId"), DataBinder.Eval(e.Row.DataItem, "CarModelId"));
            }
            

        }

    }

    private void CheckMainPageAccess()
    {
        Int64 PageAccess = General.GetProviderMainPageAccess(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()),
                                                        Convert.ToInt64(Session[General.UserId].ToString()), PageName);
        if (PageAccess == 0)
        {
            //Response.Redirect("~/Provider/UserMessage.aspx?errorcode=2000");
            Response.Redirect("~/Provider/UserMessage.aspx?mt=UM&ec=2000");
        }
    }

    private void CheckSubPageAccess()
    {
        Int64 PageAccess = General.GetProviderSubPageAccess(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()),
                                                        Convert.ToInt64(Session[General.UserId].ToString()), SubPageName);
        if (PageAccess == 0)
        {
            //Response.Redirect("~/Provider/UserMessage.aspx?errorcode=2000");
            Response.Redirect("~/Provider/UserMessage.aspx?mt=UM&ec=2000");
        }
        else if (PageAccess == 100)
        {
            lnkNew.Visible = false;
        }
    }

}
